package com.newegg.datafeed.adserving.util;

import java.security.MessageDigest;

import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class TokenUtil {
	
	@Value("${adserving.login.publicKey:c40727c66d04b725818d4579040bcc69d5cfd9b430889a1af92f02e2cdb1bde2}")
	String publicKey;
	
	public String getToken(String security){
		if(security == null){ return null; }
		MessageDigest digest = DigestUtils.getSha256Digest();
		digest.update(publicKey.getBytes());
		digest.update(security.getBytes());
		return DigestUtils.sha1Hex(digest.digest());
	}
}
